﻿using System;
using Serilog;
using LF.Domain.Services;
using LF.Shared.Dtos.Out;
using Volo.Abp.ObjectMapping;

namespace LF.Application.Services.Iml
{
    public class BaseService
    {
        protected IObjectMapper<LFModule> _mapper;
        protected IGlobalManagerService _globalManager;
        protected ILogger _logger;
        public BaseService(IObjectMapper<LFModule> mapper, IGlobalManagerService globalManager)
        {
            _mapper = mapper;
            _globalManager = globalManager;
            _logger = Log.Logger;

        }

        protected Result Ok(string msg = "操作成功")
        {
            return new Result { Data = msg, Code = Code.Ok, Message = msg };
        }
        protected Result<T> Ok<T>(T? data, string msg = "操作成功")
        {
            return new Result<T> { Data = data, Code = Code.Ok, Message = msg };
        }
        protected Result Error(string msg)
        {
            return new Result { Data = msg, Code = Code.Error, Message = msg };
        }
        protected Result<T> Error<T>(T? data, string msg = "操作失败")
        {
            return new Result<T> { Data = data, Code = Code.Error, Message = msg };
        }
        protected Result<T> Error<T>(string msg = "操作失败")
        {
            return new Result<T> { Data = default(T), Code = Code.Error, Message = msg };
        }

        protected void Warning(string msg)
        {
            _logger.Warning(msg);
        }

        protected void Warning(string msg,params object[] data)
        {
            if (data.Length > 0)
            {
                string[] arr = data.Select(p => System.Text.Json.JsonSerializer.Serialize(p)).ToArray(); ;
                _logger.Warning(string.Format(msg, data));

            }
        }
    }
}

